﻿<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="AquariumFishList.aspx.vb" Inherits="FishTank.AquariumFishList" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h1>Contained fish in your aquarium:  
        <asp:Label ID="TitleLabel" runat="server" Text=""></asp:Label>
    </h1>
    
    <asp:FormView ID="FishFormView" runat="server" width="100%" CssClass="detailView" Visible="false">
        <EditItemTemplate>
            <h1>Edit your fish</h1>
            
            <span class="failureNotification">
                <asp:Literal ID="FailureText" runat="server"></asp:Literal>
            </span>
            <asp:ValidationSummary ID="AquariumValidationSummary" runat="server" CssClass="failureNotification" 
                    ValidationGroup="AquariumValidationGroup"/>

            <div class="itemInfo">
            <fieldset class="item">
                <legend>Fish Information</legend>
                <p>
                    <asp:Label ID="SpeciesLabel" runat="server">Species:</asp:Label><br />
                    <span class="bold"><asp:Label ID="CommonNameLabel" runat="server" Text='<%# Bind("CommonName") %>'></asp:Label>
                    (<asp:Label ID="SciNameLabel" runat="server" Text='<%# Bind("ScientificName") %>'></asp:Label>)</span>
                </p>
                <p>
                    <asp:Label ID="TotalFishLabel" runat=
                        "server" AssociatedControlID="TotalFishTextBox">Total fish number:</asp:Label>
                    <asp:TextBox ID="TotalFishTextBox" runat="server" Width="32" Text='<%# Bind("Total") %>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="TotalRequiredValidator" runat="server" ControlToValidate="TotalFishTextBox" 
                        CssClass="failureNotification" ErrorMessage="Total fish number is required." ToolTip="Total fish number is required." 
                        ValidationGroup="AquariumValidationGroup">*</asp:RequiredFieldValidator>
                    <asp:RangeValidator ID="CleanPeriodRangeValidator" runat="server" ControlToValidate="TotalFishTextBox" 
                        ErrorMessage="Total fish minimum value is 1 and maximum is 100."
                        MinimumValue="1" MaximumValue="100" Type="Integer"
                        Display="None" ValidationGroup="AquariumValidationGroup"></asp:RangeValidator>
                    <asp:CompareValidator ID="TotalFishCompareValidator" runat="server" 
                        ControlToValidate="TotalFishTextBox" Display="None"
                        ErrorMessage="Total fish number is not a whole number"
                        Operator="DataTypeCheck" Type="Integer"
                        ValidationGroup="AquariumValidationGroup"></asp:CompareValidator>
                </p>
                <p>
                    <asp:Label ID="PhotoLabel" runat="server" AssociatedControlID="PhotoFileUpload">Upload a Photo:</asp:Label>
                    <asp:FileUpload ID="PhotoFileUpload" runat="server" CssClass="fileUpload" />
                    <asp:RegularExpressionValidator ID="FileExtValidator" runat="server"
                        ValidationExpression="(.*\.([gG][iI][fF]|[jJ][pP][gG]|[jJ][pP][eE][gG]|[pP][nN][gG])$)"  
                        ControlToValidate="PhotoFileUpload" ErrorMessage="Only jpg/gif/png photos are supported."
                        ValidationGroup="AquariumValidationGroup" Display="None"></asp:RegularExpressionValidator>
                </p>
                <p>
                    <asp:Label ID="CurrentPhotoLabel" runat="server" AssociatedControlID="PhotoFileUpload">Current Photo:</asp:Label>
                    <asp:Image ID="PhotoImage" runat="server"
                            ImageUrl='<%# GetPhotoNormalPath(CULng(Eval("PhotoID"))) %>'
                            AlternateText="<%# Bind('CommonName') %>"
                            CssClass="centered" />
                </p>
            </fieldset>
            <p class="submitButton">
                <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                            onclick="DeleteButton_Click" Text="Delete" />
                &nbsp;&nbsp;
                <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" 
                    ValidationGroup="AquariumValidationGroup" CausesValidation="False"
                    onclick="CancelEditButton_Click"/>
                <asp:Button ID="SaveButton" runat="server" CommandName="Save" Text="Save" 
                    ValidationGroup="AquariumValidationGroup" onclick="SaveButton_Click"/>
            </p>
            </div>
        </EditItemTemplate>

        <InsertItemTemplate>
            <h1>Add your fish</h1>

            <span class="failureNotification">
                <asp:Literal ID="FailureText" runat="server"></asp:Literal>
            </span>
            <asp:ValidationSummary ID="AquariumValidationSummary" runat="server" CssClass="failureNotification" 
                    ValidationGroup="AquariumValidationGroup"/>

            <div class="itemInfo">
            <fieldset class="item">
                <legend>Fish Information</legend>
                <p>
                    <asp:Label ID="SpeciesLabel" runat="server" AssociatedControlID="SpeciesList">Species:</asp:Label>
                    <asp:DropDownList ID="SpeciesList" runat="server" DataTextField="FullTitle" DataValueField="ID"></asp:DropDownList>
                    <asp:Label ID="AllSpeciesLabel" runat="server" Visible="false">All species exist in your aquarium. Add more species to the Fish database.</asp:Label>
                    <asp:RequiredFieldValidator ID="SpeciesRequiredValidator" runat="server" ControlToValidate="SpeciesList" 
                            CssClass="failureNotification" ErrorMessage="Species is required." ToolTip="Species is required." 
                            ValidationGroup="AquariumValidationGroup">*</asp:RequiredFieldValidator>
                </p>
                <p>
                    <asp:Label ID="TotalFishLabel" runat="server" AssociatedControlID="TotalFishTextBox">Total fish number:</asp:Label>
                    <asp:TextBox ID="TotalFishTextBox" runat="server" Width="32">1</asp:TextBox>
                    <asp:RequiredFieldValidator ID="TotalRequiredValidator" runat="server" ControlToValidate="TotalFishTextBox" 
                        CssClass="failureNotification" ErrorMessage="Total fish number is required." ToolTip="Total fish number is required." 
                        ValidationGroup="AquariumValidationGroup">*</asp:RequiredFieldValidator>
                    <asp:RangeValidator ID="CleanPeriodRangeValidator" runat="server" ControlToValidate="TotalFishTextBox" 
                        ErrorMessage="Total fish minimum value is 1 and maximum is 100."
                        MinimumValue="1" MaximumValue="100" Type="Integer"
                        Display="None" ValidationGroup="AquariumValidationGroup"></asp:RangeValidator>
                    <asp:CompareValidator ID="TotalFishCompareValidator" runat="server" 
                        ControlToValidate="TotalFishTextBox" Display="None"
                        ErrorMessage="Total fish number is not a whole number"
                        Operator="DataTypeCheck" Type="Integer"
                        ValidationGroup="AquariumValidationGroup"></asp:CompareValidator>
                </p>
                <p>
                    <asp:Label ID="PhotoLabel" runat="server" AssociatedControlID="PhotoFileUpload">Upload a Photo:</asp:Label>
                    <asp:FileUpload ID="PhotoFileUpload" runat="server" CssClass="fileUpload" />
                    <asp:RegularExpressionValidator ID="FileExtValidator" runat="server"
                        ValidationExpression="(.*\.([gG][iI][fF]|[jJ][pP][gG]|[jJ][pP][eE][gG]|[pP][nN][gG])$)"  
                        ControlToValidate="PhotoFileUpload" ErrorMessage="Only jpg/gif/png photos are supported."
                        ValidationGroup="AquariumValidationGroup" Display="None"></asp:RegularExpressionValidator>
                </p>
            </fieldset>
            <p class="submitButton">
                <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" 
                    ValidationGroup="AquariumValidationGroup" CausesValidation="False" 
                    OnClick="CancelSubmitButton_Click" />
                <asp:Button ID="SubmitButton" runat="server" CommandName="Submit" Text="Submit" 
                    ValidationGroup="AquariumValidationGroup" Onclick="SubmitButton_Click"/>
            </p>
            </div>
        </InsertItemTemplate>
    </asp:FormView>

    <p>
        <asp:ListView ID="ListGrid" runat="server" GroupItemCount="4">
            <EmptyDataTemplate>
                This aquarium has no fish yet!
            </EmptyDataTemplate>
            
            <GroupTemplate>
                <tr ID="itemPlaceholderContainer" runat="server">
                    <td ID="itemPlaceholder" runat="server">
                    </td>
                </tr>
            </GroupTemplate>
            <ItemTemplate>
                <td id="Td1" runat="server">
                    <div class="thumbnail">
                        <a href='/Pages/AquariumFishList.aspx?AID=<%# Eval("ID") %>&amp;FID=<%# Eval("FishID") %>&amp;Action=Edit'>
                        <asp:Image ID="PhotoImage" runat="server"
                                    ImageUrl='<%# GetPhotoThumbPath(CULng(Eval("PhotoID"))) %>'
                                    AlternateText="<%# Bind('CommonName') %>" />
                        </a>
                    </div>
                    <div class="caption">
                        <a href='/Pages/AquariumFishList.aspx?AID=<%# Eval("ID") %>&amp;FID=<%# Eval("FishID") %>&amp;Action=Edit'>
                        <asp:Label ID="TotalLabel" runat="server" Text="<%# Bind('Total') %>" />
                        <asp:Label ID="TitleLabel" runat="server" Text="<%# Bind('CommonName') %>" /><br />
                        (<asp:Label ID="ScientificNameLabel" runat="server" Text="<%# Bind('ScientificName') %>" />)<br />
                        * Click to edit *
                        </a>
                    </div>
                </td>
            </ItemTemplate>
            <LayoutTemplate>
                <table id="Table1" runat="server" class="listView">
                    <tr id="Tr1" runat="server">
                        <td id="Td2" runat="server">
                            <table ID="groupPlaceholderContainer" runat="server" border="0">
                                <tr ID="groupPlaceholder" runat="server">
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr id="Tr2" runat="server">
                        <td id="Td3" runat="server">
                        </td>
                    </tr>
                </table>
            </LayoutTemplate>
        </asp:ListView>
    </p>

    <p class="submitButton">
        <asp:Button ID="CreateButton" runat="server" CommandName="Create" Text="Add a fish" />
    </p>
</asp:Content>
